package cn.ncu.wechat.controller;

import cn.ncu.wechat.service.ThirdPartyApiClientService;
import cn.ncu.wechat.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Optional;

@RestController
public class ThirdPartyApiClientController {
    @Autowired
    private ThirdPartyApiClientService thirdPartyApiClientService;

    @GetMapping ("/api/admin/MemberCard")
    public ResponseEntity<?> getMemberCardType(@RequestParam(required = false) String mtyCode,
                                               @RequestParam(required = false) String mtyName,
                                               @RequestParam(required = false) String sort,
                                               @RequestParam(required = false) Integer page,
                                               @RequestParam(required = false) Integer size){
        System.out.println("getMemberCardType========================");

        return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON_UTF8).body(thirdPartyApiClientService.getCardType(Optional.ofNullable(mtyCode).orElse(""), // 如果为空，传递空字符串
                Optional.ofNullable(mtyName).orElse(""), // 如果为空，传递空字符串
                Optional.ofNullable(sort).orElse(""),     // 如果为空，传递空字符串
                Optional.ofNullable(page).orElse(1),      // 如果为空，传递默认值 1
                Optional.ofNullable(size).orElse(10)));
    }

    @GetMapping("/api/admin/OrderRecord")
    public ResponseEntity<?>  getOrderRecord(@RequestParam(required = false) String ctpCtmcode,
                                             @RequestParam(required = false) String ctpStatus,
                                             @RequestParam(required = false) Integer currentPage,
                                             @RequestParam(required = false) String endDate,
                                             @RequestParam(required = false) String sort,
                                             @RequestParam(required = false) Integer size) {
        return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON_UTF8).body(thirdPartyApiClientService.getOrders(Optional.ofNullable(ctpCtmcode).orElse(""), // 如果为空，传递空字符串
                Optional.ofNullable(ctpStatus).orElse(""),
                Optional.ofNullable(currentPage).orElse(1),
                Optional.ofNullable(endDate).orElse(""),
                Optional.ofNullable(sort).orElse(""),     // 如果为空，传递默认值 1
                Optional.ofNullable(size).orElse(10)));
    }
}
